package com.chixing.day02;

import java.util.Arrays;

/*
    数组
    引用数据类型的默认值：null
*/
public class ArrayDemo {
    public static void main(String[] args) {

        int[] arr1 = {10, 5, 23, 54, 23};
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i]);
        }
        System.out.println();

        int[] arr2 = new int[5];//5：元素个数
        for (int j = 0; j < arr2.length; j++) {
            System.out.print(arr2[j]);
        }
        System.out.println();

        float[] arr3 = {9.9f, 4.5f, 3.6f, 12};
        float[] arr4 = new float[5];

        arr1 = null;//表示指针断开

        System.out.println(arr3[0]);
        //System.out.println(arr3[6]);//ArrayIndexOutOfBoundsException

        int[][] arr5 = new int[2][5];
        //2行3列
        int[][] a = {{11, 25, 24}, {45, 22, 63}};
        System.out.println("a[0][2]:" + a[0][2]);
        System.out.println("a数组的行数:" + a.length);//行数 2
        System.out.println("a数组的列数:" + a[0].length);//列数 3
        int[][] b = new int[2][3];

        int[][] c = new int[2][];//错误的定义方式
        System.out.println("c数组的行数:" + c.length);//行数 2
        //c[0][0] = 1;//错误的


        //数组的工具类:Arrays
        int[] arr6 = {10, 5, 23, 54, 23};
        int[] newArr = Arrays.copyOf(arr6,10);
        for (int i = 0; i < newArr.length; i++) {
            System.out.print(newArr[i] + ",");
        }
        System.out.println();




    }

    public static int fun1(){
        //三目运算
        int x=10;
        int y=20;
        return (x>y)?x:y;
    }

}
